<?
// if (!$userID) die('User ID was not defined');
if (!$_GET[thestyle]) {
	echo "style not defined.";
	die();
	}
$filename = str_replace('..', '', $_GET[thestyle]);

if (file_exists($filename)) $cssfile = file($filename);
else die("CSS file $filename doesn't exist.");

if ($cssfile) {
	while (list (,$line) = each($cssfile)) {
		$line = trim($line);
		if ($line) {
			eregi('([^\{]*)\{([^\}]*)\}',$line,$reg);
			$selector = trim($reg[1]);
			$rules = trim($reg[2]);
			if ($selector && $rules) {
				$defs = explode(";",$rules);
				while (list(,$rule) = each($defs)) {
					list($prop,$def) = explode(":",$rule);
					$prop = trim($prop);
					$def = trim($def);
					if ($prop!='' && def!='') $css[$selector][$prop] = $def;
					}
				}
			}
		}
	}

else die("CSS file $filename is empty.");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
	<title>CSS Editor of <? echo htmlspecialchars($sel) ?></title>
	<meta name="copyright" content="pixy@pixy.cz" />
	<script src="js/utils.js" type="text/javascript"></script>

<style type="text/css">
	th {
		font-family: monospace;
		background-color:#eeeeee;
		font-size:small;
		border-width:0 0 1px 0;
		border-style:solid;
		border-color:silver;
		text-align:left;
		white-space: nowrap;
		padding: 0.2ex 1ex
		}
	td {
		font-family: monospace;
		font-size:small;
		border-width:0 0 1px 0;
		border-style:solid;
		border-color:silver;
		text-align:left;
		padding: 0.2ex 1ex
		}
</style>

</head>

<body>

<table cellspacing="0">

<?

while (list($s,$r) = each ($css)) {
	$rule = '';
	while (list($p,$d) = each($r))
		if ($d!='') $rule .= $p.": ".$d."; ";
	if ($rule) {
		echo "<tr><th>";
		echo " <a href='csseditor.php?thestyle=".rawurlencode($filename)."&sel=".urlencode($s)."&thepage=".rawurlencode($_GET[thepage])."'>".$s."</a>  </th>
		<th align='right'><a href='csseditor.php?thestyle=".rawurlencode($filename)."&sel=".urlencode($s)."&thepage=".rawurlencode($thepage)."&delete=yes'>[delete]</a>  </th>\n";
		echo "<td> { $rule} </td></tr>\n";
		}
	}

?>

</table>

</body>
</html>
